package com.luban.test;

import com.luban.annotations.CssStyle;
import com.luban.enums.CssStyleEnum;

import java.lang.reflect.Field;

public class User {
	@CssStyle(style = CssStyleEnum.css)
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public static void main(String[] args) throws IllegalAccessException {
		User user = new User();
		user.setName("jym");
		Field[] fields = user.getClass().getDeclaredFields();
		for (Field field : fields) {
			CssStyle cssStyle = field.getDeclaredAnnotation(CssStyle.class);
			if(cssStyle != null){
				String value = (String)field.get(user);
				CssStyleEnum cssStyleEnum = cssStyle.style();
				String enumValue = cssStyleEnum.getValue();
				if(enumValue.contains("?")){
					enumValue = enumValue.replace("?",value);
					field.set(user,enumValue);
				}
			}
		}

		System.out.println(user.getName());
	}
}
